package com.earthea.application.common.enums;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * 操作人类别
 */
@Getter
public enum OperatorType {
    /**
     * 其它
     */
    OTHER(0, "其他"),

    /**
     * 后台用户
     */
    MANAGE(1, "后台用户"),

    /**
     * 手机端用户
     */
    MOBILE(2, "手机端用户"),
    ;

    private final int value;

    private final String label;

    OperatorType(int value, String label) {
        this.value = value;
        this.label = label;
    }

    public static String getLabel(int value) {
        return Arrays.stream(values()).filter(type -> type.getValue() == value).findFirst().map(OperatorType::getLabel).orElse(OperatorType.OTHER.getLabel());
    }

    public static int getValue(String label) {
        return Arrays.stream(values()).filter(type -> StringUtils.equals(type.getLabel(), label)).findFirst().map(OperatorType::getValue).orElse(OperatorType.OTHER.getValue());
    }

}
